@echo off
REM 设置binlog存放目录
set BINLOG_PATH=C:\ProgramData\MySQL\MySQL Server 8.0\Data
REM 设置备份保存路径
set BACKUP_PATH=E:\mysql_binlog_backup
REM 设置日期变量
set DATE=%date:~0,4%%date:~5,2%%date:~8,2%

REM 创建备份目录（如果不存在）
if not exist %BACKUP_PATH%\%DATE% (
    mkdir %BACKUP_PATH%\%DATE%
)

REM 复制binlog文件到备份目录（只复制*.000*文件，避免复制index文件）
copy %BINLOG_PATH%\*.000* %BACKUP_PATH%\%DATE%\

REM 可选：删除7天前的binlog备份
forfiles /p %BACKUP_PATH% /d -7 /c "cmd /c rd /s /q @path"
